<template>
    <div class="source">
        <!-- 来源文件管理弹窗 -->
        <el-dialog :title="title" :visible.sync="dialogVisible" width="75%" :close-on-click-modal="false">
            <div>
                <div style="border: 1px solid #a4a4a4">
                    <el-form :inline="true" :model="indexSourceCategoryDetailPo" style="margin-top: 20px">
                        <el-row class="form-row">
                            <el-col :span="12">
                                <el-form-item :label="indexItem.indexType == '2' ? '产品类型：' : '来源类型：'">
                                    <span style="position: absolute; left: -10px; color: red">*</span>
                                    <el-select v-model="indexSourceCategoryDetailPo.parentId" placeholder="请选择" size="mini" disabled>
                                        <el-option
                                            :label="item.indexName"
                                            :value="item.indexDirectoryCode"
                                            v-for="item in indexSourceCodeSelect"
                                            :key="item.indexDirectoryCode"
                                            >{{ item.indexDirectoryCode }} {{ item.indexName }}</el-option
                                        >
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item :label="indexItem.indexType == '2' ? '来源产品：' : '来源名称：'">
                                    <span style="position: absolute; left: -10px; color: red">*</span>
                                    <el-input
                                        v-model="indexSourceCategoryDetailPo.label"
                                        placeholder="请输入来源名称"
                                        size="mini"
                                        style="width: 120%"
                                        v-if="indexItem.indexType != '2'"
                                        :disabled="['3', '4'].includes(indexItem.level)"
                                    ></el-input>
                                    <el-input
                                        v-model="indexSourceCategoryDetailPo.lableChild"
                                        placeholder="请输入来源名称"
                                        size="mini"
                                        style="width: 120%"
                                        v-if="indexItem.indexType == '2'"
                                        :disabled="['3', '4'].includes(indexItem.level)"
                                    ></el-input>
                                </el-form-item>
                            </el-col>
                            <!-- <el-col :span="4">
                                <el-button
                                    type="primary"
                                    size="mini"
                                    style="margin-top: 4px"
                                    @click="addFileSourceCategoryNode"
                                    v-if="indexItem.level == 3"
                                    :disabled="addDisabled"
                                    >添加</el-button
                                >
                            </el-col> -->
                        </el-row>
                    </el-form>
                </div>
                <div style="margin-top: 25px" v-if="['3', '4'].includes(indexItem.level)">
                    <div>
                        <el-button type="primary" @click="handleAddFileBtn('新增')" :disabled="!addFileBtn">新增文件</el-button>
                        <el-button type="danger" @click="comfiredMove(multipleitem, '批量删除')" :disabled="!addFileBtn">批量删除</el-button>
                    </div>
                    <el-table
                        :data="indexSourceCategoryDetail"
                        tooltip-effect="dark"
                        style="width: 100%; margin-top: 10px"
                        border
                        size="mini"
                        @selection-change="clauseChangeEvent"
                    >
                        <el-table-column type="selection" width="55"></el-table-column>
                        <el-table-column type="index" label="序号" width="50"> </el-table-column>
                        <el-table-column prop="productType" label="合同类型" width="130" show-overflow-tooltip v-if="indexItem.indexType == '2'">
                            <template slot-scope="scope">
                                <span>{{ scope.row.productType == '1' ? '资产管理合同' : scope.row.productType == '2' ? '补充协议' : '--' }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column
                            prop="versionNumber"
                            :label="indexItem.indexType == '2' ? '合同名称' : '版本号'"
                            width="130"
                            show-overflow-tooltip
                        >
                        </el-table-column>
                        <el-table-column v-if="indexItem.indexType !== '2'" prop="fileName" label="文件名称" min-width="170" show-overflow-tooltip>
                            <template slot-scope="scope">
                                <span>{{ scope.row.fileName.length == 0 ? '--' : scope.row.fileName.join(',') }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column
                            :prop="issueDate"
                            :label="indexItem.indexType == '2' ? '签署日期' : '发布日期'"
                            width="130"
                            show-overflow-tooltip
                        >
                            <template slot-scope="scope">
                                <span>{{ dateFormat(scope.row.issueDate) || '--' }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="effectiveDate" label="生效日期" width="120" show-overflow-tooltip>
                            <template slot-scope="scope">
                                <span>{{ dateFormat(scope.row.effectiveDate) || '--' }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="valid" label="是否有效" width="120" show-overflow-tooltip align="center">
                            <template slot-scope="scope">
                                <el-dropdown @command="handleCommand">
                                    <span class="el-dropdown-link"
                                        >{{ scope.row.valid == '1' ? '是' : '否' }}<i class="el-icon-arrow-down el-icon--right"></i>
                                    </span>
                                    <el-dropdown-menu slot="dropdown">
                                        <el-dropdown-item :command="beforeHandleCommand('1', scope.row)">是</el-dropdown-item>
                                        <el-dropdown-item :command="beforeHandleCommand('0', scope.row)">否</el-dropdown-item>
                                    </el-dropdown-menu>
                                </el-dropdown>
                            </template>
                        </el-table-column>
                        <el-table-column prop="modifyUser" label="维护人" width="140" show-overflow-tooltip> </el-table-column>
                        <el-table-column prop="modifyDate" label="维护日期" width="120" show-overflow-tooltip>
                            <template slot-scope="scope">
                                <span>{{ dateFormat(scope.row.modifyDate) || '--' }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column label="操作" width="150" fixed="right">
                            <template slot-scope="scope">
                                <RiskIconButton
                                    type="primary"
                                    icon="el-icon-edit"
                                    topTitle="修改"
                                    v-authCode="B_0188"
                                    @on-click="openAttachementDialog(scope.row, '修改')"
                                ></RiskIconButton>
                                <RiskIconButton
                                    type="primary"
                                    icon="el-icon-download"
                                    topTitle="下载"
                                    v-authCode="B_0188"
                                    @on-click="downloadFileBtn(scope.row, '单条下载')"
                                ></RiskIconButton>
                                <RiskIconButton
                                    type="danger"
                                    icon="el-icon-delete"
                                    topTitle="删除"
                                    v-authCode="B_0191"
                                    @on-click="comfiredMove(scope.row, '单个删除')"
                                ></RiskIconButton>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
                <div style="margin-top: 20px" v-else>
                    <h2>版本内容维护</h2>
                    <div style="border: 1px solid #a4a4a4">
                        <el-form :inline="true" :model="indexDetails" :label-position="right" label-width="100px" style="margin-top: 15px">
                            <el-row class="form-row" v-if="['监管类', '制度解读类'].includes(MenuName)">
                                <el-col :span="12">
                                    <el-form-item label="版本号">
                                        <span style="position: absolute; left: -10px; color: red">*</span>
                                        <el-input v-model="indexDetails.versionNumber" size="mini" style="width: 105%" maxlength="20"></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="是否有效">
                                        <el-select v-model="indexDetails.valid" placeholder="请选择" size="mini">
                                            <el-option label="有效" value="1"></el-option>
                                            <el-option label="无效" value="0"></el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row class="form-row" v-else-if="MenuName == '合同类'">
                                <el-col :span="12">
                                    <el-form-item label="合同名称">
                                        <el-input v-model="indexDetails.versionNumber" size="mini" style="width: 105%" maxlength="20"></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="合同类型">
                                        <span style="position: absolute; left: -10px; color: red">*</span>
                                        <el-select v-model="indexDetails.productType" placeholder="请选择" size="mini" clearable>
                                            <el-option label="资产管理合同" value="1" key="1"></el-option>
                                            <el-option label="补充协议" value="2" key="2"></el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row class="form-row">
                                <el-col :span="12">
                                    <el-form-item label="发布日期" v-if="['监管类', '制度解读类'].includes(MenuName)">
                                        <el-date-picker
                                            v-model="indexDetails.issueDate"
                                            placeholder="选择日期"
                                            size="mini"
                                            style="width: 94%"
                                            format="yyyy-MM-dd"
                                            value-format="yyyyMMdd"
                                        >
                                        </el-date-picker>
                                    </el-form-item>
                                    <el-form-item label="签署日期" v-else-if="MenuName == '合同类'">
                                        <el-date-picker
                                            v-model="indexDetails.issueDate"
                                            placeholder="选择日期"
                                            size="mini"
                                            style="width: 94%"
                                            format="yyyy-MM-dd"
                                            value-format="yyyyMMdd"
                                        >
                                        </el-date-picker>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="生效日期">
                                        <el-date-picker
                                            v-model="indexDetails.effectiveDate"
                                            placeholder="选择日期"
                                            size="mini"
                                            style="width: 94%"
                                            format="yyyy-MM-dd"
                                            value-format="yyyyMMdd"
                                        >
                                        </el-date-picker>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row class="form-row">
                                <el-col :span="12">
                                    <el-form-item label="迁移条文">
                                        <el-select
                                            v-model="indexDetails.moveIndexArticleCode"
                                            filterable
                                            clearable
                                            placeholder="请选择"
                                            size="mini"
                                            :disabled="moveIndexSourceIs"
                                            @change="changeMovedIndexSource"
                                        >
                                            <el-option
                                                :label="item.articleName"
                                                :value="item.articleCode"
                                                v-for="item in indexSourceCodeSelect1"
                                                :key="item.articleCode"
                                                >{{ item.articleName }}</el-option
                                            >
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="迁移版本" v-if="['监管类', '制度解读类'].includes(MenuName)">
                                        <el-select
                                            v-model="indexDetails.moveIndexArticleDetailsCode"
                                            filterable
                                            clearable
                                            placeholder="请选择"
                                            size="mini"
                                            :disabled="moveIndexSourceIs"
                                        >
                                            <el-option
                                                :label="item.versionNumber"
                                                :value="item.articleDeatilsCode"
                                                v-for="item in moveIndexArticleCodeList"
                                                :key="item.articleDeatilsCode"
                                                >{{ item.versionNumber }}</el-option
                                            >
                                        </el-select>
                                    </el-form-item>
                                    <el-form-item label="是否有效" v-else-if="MenuName == '合同类'">
                                        <el-select v-model="indexDetails.valid" placeholder="请选择" size="mini">
                                            <el-option label="有效" value="1"></el-option>
                                            <el-option label="无效" value="0"></el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row class="form-row">
                                <el-col :span="12">
                                    <el-form-item label="附件">
                                        <el-upload
                                            :multiple="true"
                                            :action="actionUrl"
                                            :headers="headerObj"
                                            :with-credentials="true"
                                            list-type="text"
                                            :show-file-list="false"
                                            :on-success="
                                                (res, file, fileList) => {
                                                    return uploadFileSuccess(res, file, fileList, '执行标准');
                                                }
                                            "
                                            :on-error="
                                                (res, file, fileList) => {
                                                    return uploadFileError(res, file, fileList, '执行标准');
                                                }
                                            "
                                        >
                                            <el-button size="small" icon="el-icon-plus" style="border: none">添加文件</el-button>
                                        </el-upload>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <UploadFileShow
                                style="margin-left: 60px"
                                :fileList="fileList1"
                                @emitDownLoadFile="downLoadFileBtn2"
                                @emitConfirmDelFile="confirmDelFile1"
                            ></UploadFileShow>
                        </el-form>
                    </div>
                </div>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="handleSource('cancel')">{{ indexItem.level == 2 ? '取 消' : '关 闭' }}</el-button>
                <el-button type="primary" @click="handleSource('confirm')" v-if="indexItem.level == 2">确 定</el-button>
            </span>
        </el-dialog>
        <!-- 附件上传弹窗 -->
        <el-dialog title="附件上传内容填写" :visible.sync="attachementDialog" width="60%" :close-on-click-modal="false">
            <div>
                <el-form :inline="true" :model="indexDetails" :label-position="right" label-width="100px">
                    <el-row class="form-row" v-if="['监管类', '制度解读类'].includes(MenuName)">
                        <el-col :span="12">
                            <el-form-item label="版本号">
                                <span style="position: absolute; left: -10px; color: red">*</span>
                                <el-input v-model="indexDetails.versionNumber" size="mini" style="width: 105%" maxlength="20"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="是否有效">
                                <el-select v-model="indexDetails.valid" placeholder="请选择" size="mini">
                                    <el-option label="有效" value="1"></el-option>
                                    <el-option label="无效" value="0"></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row class="form-row" v-else-if="MenuName == '合同类'">
                        <el-col :span="12">
                            <el-form-item label="合同名称">
                                <span style="position: absolute; left: -10px; color: red">*</span>
                                <el-input v-model="indexDetails.versionNumber" size="mini" style="width: 105%" maxlength="20"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="合同类型">
                                <span style="position: absolute; left: -10px; color: red">*</span>
                                <el-select v-model="indexDetails.productType" placeholder="请选择" size="mini" clearable>
                                    <el-option label="资产管理合同" value="1" key="1"></el-option>
                                    <el-option label="补充协议" value="2" key="2"></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row class="form-row">
                        <el-col :span="12">
                            <el-form-item label="发布日期" v-if="['监管类', '制度解读类'].includes(MenuName)">
                                <el-date-picker
                                    v-model="indexDetails.issueDate"
                                    placeholder="选择日期"
                                    size="mini"
                                    style="width: 94%"
                                    format="yyyy-MM-dd"
                                    value-format="yyyyMMdd"
                                >
                                </el-date-picker>
                            </el-form-item>
                            <el-form-item label="签署日期" v-else-if="MenuName == '合同类'">
                                <el-date-picker
                                    v-model="indexDetails.issueDate"
                                    placeholder="选择日期"
                                    size="mini"
                                    style="width: 94%"
                                    format="yyyy-MM-dd"
                                    value-format="yyyyMMdd"
                                >
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="生效日期">
                                <el-date-picker
                                    v-model="indexDetails.effectiveDate"
                                    placeholder="选择日期"
                                    size="mini"
                                    style="width: 94%"
                                    format="yyyy-MM-dd"
                                    value-format="yyyyMMdd"
                                >
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row class="form-row">
                        <el-col :span="12">
                            <el-form-item label="迁移条文">
                                <el-select
                                    v-model="indexDetails.moveIndexArticleCode"
                                    filterable
                                    clearable
                                    placeholder="请选择"
                                    size="mini"
                                    @change="changeMovedIndexSource"
                                >
                                    <el-option
                                        :label="item.articleName"
                                        :value="item.articleCode"
                                        v-for="item in indexSourceCodeSelect1"
                                        :key="item.articleCode"
                                        >{{ item.articleName }}</el-option
                                    >
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="迁移版本" v-if="['监管类', '制度解读类'].includes(MenuName)">
                                <el-select
                                    v-model="indexDetails.moveIndexArticleDetailsCode"
                                    filterable
                                    clearable
                                    placeholder="请选择"
                                    size="mini"
                                >
                                    <el-option
                                        :label="item.versionNumber"
                                        :value="item.articleDeatilsCode"
                                        v-for="item in moveIndexArticleCodeList"
                                        :key="item.articleDeatilsCode"
                                        >{{ item.versionNumber }}</el-option
                                    >
                                </el-select>
                            </el-form-item>
                            <el-form-item label="是否有效" v-else-if="MenuName == '合同类'">
                                <el-select v-model="indexDetails.valid" placeholder="请选择" size="mini">
                                    <el-option label="有效" value="1"></el-option>
                                    <el-option label="无效" value="0"></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row class="form-row">
                        <el-col :span="12">
                            <el-form-item label="附件">
                                <el-upload
                                    :multiple="true"
                                    :action="actionUrl"
                                    :headers="headerObj"
                                    :with-credentials="true"
                                    list-type="text"
                                    :show-file-list="false"
                                    :on-success="
                                        (res, file, fileList) => {
                                            return uploadFileSuccess(res, file, fileList, '执行标准');
                                        }
                                    "
                                    :on-error="
                                        (res, file, fileList) => {
                                            return uploadFileError(res, file, fileList, '执行标准');
                                        }
                                    "
                                >
                                    <el-button size="small" icon="el-icon-plus" style="border: none">添加文件</el-button>
                                </el-upload>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <UploadFileShow
                        style="margin-left: 60px"
                        :fileList="fileList1"
                        @emitDownLoadFile="downLoadFileBtn2"
                        @emitConfirmDelFile="confirmDelFile1"
                    ></UploadFileShow>
                </el-form>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="insertSourceDetails">确 定</el-button>
            </span>
        </el-dialog>
        <template>
            <DeletionConfirmationDialog
                title="警告"
                :delConfirmationDialog="delConfirmationDialog"
                @emitDialogVisible="emitDialogVisible"
                @emitHandleBtn="handleRemove"
            >
                <div slot="content1">{{ delContent }}</div>
            </DeletionConfirmationDialog>
        </template>
    </div>
</template>
<script lang="ts">
import { Component, Vue, Prop, Watch } from 'vue-property-decorator';
import RiskIconButton from '@/common/components/risk-icon-button.vue';
import UploadFileShow from '../commom/upload-file-show.vue';
import DeletionConfirmationDialog from '../commom/deletion-confirmation-dialog.vue';
import { dateFormat, timeFormat, getConfigItem } from '@/utils/tools';
import { getUser } from '@/utils/user-util';
import { downLoadFile } from '@/utils/request';
import XEUtils from 'xe-utils';
import moment from 'moment';
import JSEncrypt from 'jsencrypt';
@Component({
    name: 'SourceDocumentDialog',
    components: {
        RiskIconButton,
        UploadFileShow,
        DeletionConfirmationDialog,
    },
})
export default class SourceDocumentDialog extends Vue {
    BASE_URL_API = getConfigItem('BASE_URL_API');
    dateFormat = dateFormat;
    @Prop() addSourceDialog;
    @Prop() indexItem;
    @Prop() indexClauseList;
    @Prop() MenuName;
    private dialogVisible: boolean = false;
    private attachementDialog: boolean = false;
    indexSourceCodeSelect = []; // 条目来源分类下拉
    addFileBtn: boolean = false; // 新增文件btn
    indexSourceCategoryDetail = []; // 来源详情信息
    private indexSourceCodeSelect1 = []; // 来源名称select
    private moveIndexArticleCodeList = []; // 迁移版本号select
    typeItem: string = ''; // 新增、编辑
    private actionUrl = ''; // 附件上传url
    fileList1 = []; // 附件
    multipleitem = []; // table多选
    delBtnDisabled: boolean = false;
    delConfirmationDialog: boolean = false;
    headerObj = {
        Authentication: getUser().sessionId,
    };
    indexSourceCategoryDetailPo = {
        indexType: '1', // 指标类型：1:外规类指标、2:产品类指标
        parentId: '', // 来源类型
        label: '', // 指标来源名称
        lableChild: '',
    };
    validTable: string = '是';
    indexDetails = {
        // 来源详情信息
        articleCode: '',
        articleDeatilsCode: '',
        indexDirectoryCode: '',
        effectiveDate: '',
        fileCode: [],
        fileName: [],
        issueDate: '',
        moveIndexArticleCode: '',
        moveIndexArticleDetailsCode: '',
        valid: '1',
        versionNumber: '',
        // signDate: '',
        files: [],
        indexType: '',
        productType: '',
    };
    addDisabled: boolean = false;
    moveIndexSourceIs: boolean = false;
    delContent: string = '是否删除所选来源文件？';
    title = '';
    delData = {
        singData: '',
        moreData: [],
        type: '',
    };
    flag = false; // 判断是否已使用迁移条文
    rsaPassWord: any = null; // 加密

    created() {
        // const baseUrl = process.env.ENV_CONFIG === 'project' ? window.project_config.BASE_URL_API : process.env.BASE_URL_API;
        // this.actionUrl = baseUrl + '/system/upload/1';
        this.actionUrl = this.BASE_URL_API + '/apiAssetFile/upload';
        var encryptor = new JSEncrypt(); // 创建加密对象实例
        // 之前ssl生成的公钥，复制的时候要小心不要有空格
        var pubKey =
            'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDI1/pR72vGeQoQ8YxKVrDzV6RriOkNkW0UWw4JgXhH417lULhKMQWK3GeJW+Tg0kHlhpx4iQNxrEPlroCqZfylgPI+x0AohcnvkY52VGQGLnms2tMefBKdz2BHUAp7MdF7GsGtpiHWSZbEWk5onkB7pH8Q0KlNAB+7BoNTj9MOywIDAQAB';
        encryptor.setPublicKey(pubKey); // 设置公钥
        this.rsaPassWord = encryptor.encrypt('zszg@zgssfkxt'); // 对内容进行加密
    }
    handleSource(parameter) {
        if (parameter == 'cancel') {
            this.$emit('emitSource', false, false);
            return;
        }
        if (this.indexItem.level == 2) {
            if (this.indexSourceCategoryDetailPo.label == '') {
                this.yh_message_warn(this.indexItem.indexType == '2' ? '来源产品不可为空' : '来源名称不可为空');
                return;
            }
            this.insertSourceDetails();
        } else {
            this.$emit('emitSource', false, false);
        }
    }
    @Watch('addSourceDialog')
    watchAddSourceDialog(val) {
        this.dialogVisible = val;
        if (val == true) {
            this.title = this.indexItem;
            console.log('00000', this.indexItem);
            this.getIndexSourceSelect();
            if ((this.indexItem.level == 3 && ['1', '3'].includes(this.indexItem.indexType)) || this.indexItem.level == 4) {
                this.title = '来源文件管理编辑';
                this.addFileBtn = true;
                this.indexSourceCategoryDetailPo.parentId = this.indexItem.level == 4 ? this.indexItem.productTypes : this.indexItem.parentCode;
                this.indexSourceCategoryDetailPo.label = this.indexItem.label;
                this.indexDetails.articleCode = this.indexItem.id;
                this.indexSourceCategoryDetailPo.lableChild = this.indexItem.productCode + ' ' + this.indexItem.label;
                this.getSourceDetails();
            } else if (this.indexItem.level == 2) {
                this.title = '来源文件管理新增';
                this.indexSourceCategoryDetailPo.parentId = this.indexItem.id;
                this.getIndexSourceSelect1(this.indexItem.indexType);
                this.getSourceDetails();
            }
        } else if (val == false) {
            this.fileList1 = [];
            this.addDisabled = false;
            this.indexDetails = {
                // 来源详情信息
                articleCode: this.indexItem.id,
                articleDeatilsCode: '',
                indexDirectoryCode: '',
                versionNumber: '',
                valid: '1',
                issueDate: '',
                // signDate: '',
                effectiveDate: '',
                moveIndexArticleCode: '',
                moveIndexArticleDetailsCode: '',
                fileCode: [],
                files: [],
                fileName: [],
                indexType: '',
                productType: '',
            };
        }
    }
    @Watch('dialogVisible')
    watchDialogVisible(val) {
        if (val == false) {
            this.indexSourceCategoryDetailPo.label = '';
            this.addFileBtn = false;
            this.$emit('emitAddSourceDialog', false);
        }
    }
    @Watch('attachementDialog')
    watchAttachementDialog(val) {
        console.log('4444444', this.indexItem);
        if (val == true) {
            this.moveIndexArticleCodeList = [];
            if (this.indexItem.level != 3) {
                this.indexDetails.articleCode = this.indexItem.id;
            }
            this.getIndexSourceSelect1(this.indexItem.indexType);
        } else if (val == false) {
            this.moveIndexArticleCodeList = [];
            this.fileList1 = [];
            this.indexDetails = {
                // 来源详情信息
                articleCode: this.indexItem.id,
                indexDirectoryCode: '',
                articleDeatilsCode: '',
                versionNumber: '',
                valid: '1',
                issueDate: '',
                // signDate: '',
                effectiveDate: '',
                moveIndexArticleCode: '',
                moveIndexArticleDetailsCode: '',
                fileCode: [],
                files: [],
                fileName: [],
                indexType: '',
                productType: '',
            };
            this.moveIndexSourceIs = false;
        }
    }
    @Watch('indexClauseList', { immediate: true, deep: true })
    watchIndexClauseList(val) {
        if (this.indexClauseList.length > 0) {
            this.delBtnDisabled = true;
        } else {
            this.delBtnDisabled = false;
        }
    }

    // 查询条文详情信息/articleDetails/query
    getSourceDetails() {
        this.$axios
            .post('/zhiguan/indexArticle/articleDetails/query', {
                articleCode: this.indexDetails.articleCode,
            })
            .then((res: any) => {
                this.indexSourceCategoryDetail = [];
                res.forEach(item => this.indexSourceCategoryDetail.push(item));
            });
    }
    // 新增来源详情信息
    insertSourceDetails() {
        if (this.indexDetails.versionNumber == '' && ['监管类', '制度解读类'].includes(this.MenuName)) {
            this.yh_message_warn('版本号不可为空');
            return;
        }
        if (this.indexDetails.versionNumber == '' && ['合同类'].includes(this.MenuName)) {
            this.yh_message_warn('合同名称不可为空');
            return;
        }
        if (this.indexDetails.productType == '' && ['合同类'].includes(this.MenuName)) {
            this.yh_message_warn('合同类型不可为空');
            return;
        }
        if (this.indexDetails.moveIndexArticleCode != '' && this.indexDetails.moveIndexArticleDetailsCode == '') {
            this.yh_message_warn('迁移版本号不可为空');
            return;
        }
        this.indexDetails.fileCode = [];
        this.indexDetails.fileName = [];
        this.indexDetails.files = [];
        if (this.fileList1) {
            this.fileList1.forEach(item => {
                this.indexDetails.fileCode.push(item.fileNo);
                this.indexDetails.fileName.push(item.name);
                this.indexDetails.files.push({
                    fileNo: item.fileNo,
                    fileName: item.name,
                });
            });
        }
        let dataList = {};
        dataList = {
            // 来源详情信息
            articleCode: this.indexDetails.articleCode,
            articleDeatilsCode: this.indexDetails.articleDeatilsCode,
            effectiveDate: this.indexDetails.effectiveDate,
            fileCode: this.indexDetails.fileCode,
            fileName: this.indexDetails.fileName,
            issueDate: this.indexDetails.issueDate,
            versionNumber: this.indexDetails.versionNumber,
            valid: this.indexDetails.valid,
            indexType: this.indexItem.indexType,
            moveIndexArticleCode: this.indexDetails.moveIndexArticleCode,
            moveIndexArticleDetailsCode: this.indexDetails.moveIndexArticleDetailsCode,
            indexDirectoryCode: this.indexItem.indexType == '2' ? this.indexItem.productTypes : this.indexItem.parentCode,
            productType: this.indexDetails.productType,
        };
        let flag;

        if (this.typeItem == '新增' && this.indexItem.level != 2) {
            if (this.indexItem.indexType != '2') {
                if (this.indexDetails.moveIndexArticleCode != '' && this.indexDetails.moveIndexArticleDetailsCode != '') {
                    flag = true;
                } else {
                    flag = false;
                }
            } else {
                if (this.indexDetails.moveIndexArticleCode != '') {
                    flag = true;
                } else {
                    flag = false;
                }
            }

            this.$axios.post('/zhiguan/indexArticle/articleDetails/insert', { ...dataList, flag: flag }).then((res: any) => {
                this.yh_message_success('新增成功!');
                this.attachementDialog = false;
                this.fileList1 = [];
                this.getSourceDetails();
                this.$emit('emitSource', true, true);
            });
        } else if (this.typeItem == '修改' && this.indexItem.level != 2) {
            let flag;
            if (['1', '3'].includes(this.indexItem.indexType)) {
                if (this.moveIndexSourceIs == false && this.indexDetails.moveIndexArticleCode && this.indexDetails.moveIndexArticleDetailsCode) {
                    flag = true;
                } else {
                    flag = false;
                }
            } else {
                if (this.moveIndexSourceIs == false && this.indexDetails.moveIndexArticleCode) {
                    flag = true;
                } else {
                    flag = false;
                }
            }
            this.$axios
                .post('/zhiguan/indexArticle/articleDetails/update', { ...dataList, flag: flag })
                .then((res: any) => {
                    this.yh_message_success('修改成功!');
                    this.attachementDialog = false;
                    this.fileList1 = [];
                    this.getSourceDetails();
                    this.moveIndexSourceIs = false;
                    this.$emit('emitSource', true, true);
                })
                .catch(() => {
                    this.moveIndexSourceIs = false;
                    this.attachementDialog = false;
                });
        } else if (this.indexItem.level == 2) {
            if (this.indexDetails.moveIndexArticleCode && this.indexDetails.moveIndexArticleDetailsCode) {
                flag = true;
            } else {
                flag = false;
            }
            this.$axios
                .post('/zhiguan/indexArticle/article/details/insert', {
                    indexArticleDetailsPO: { ...dataList, flag },
                    articleName: this.indexSourceCategoryDetailPo.label,
                    indexDirectoryCode: this.indexSourceCategoryDetailPo.parentId,
                    indexType: this.indexItem.indexType,
                })
                .then((res: any) => {
                    this.yh_message_success('添加成功!');
                    this.attachementDialog = false;
                    this.fileList1 = [];
                    this.moveIndexSourceIs = false;
                    this.$emit('emitSource', false, true);
                })
                .catch(() => {
                    this.moveIndexSourceIs = false;
                    this.attachementDialog = false;
                });
        }
    }
    // 查询来源目录信息--来源类型
    getIndexSourceSelect() {
        if (this.indexItem.indexType != '2') {
            this.$axios.post('/zhiguan/indexArticle/directory/query', { parentCode: '' }).then((res: any) => {
                if (res) {
                    this.indexSourceCodeSelect = [];
                    res.forEach(item => this.indexSourceCodeSelect.push(item));
                }
            });
        } else if (this.indexItem.indexType == '2') {
            this.indexSourceCodeSelect = [];
            this.indexSourceCodeSelect = [
                {
                    indexDirectoryCode: '5',
                    indexName: '公募',
                    level: '3',
                    indexType: '2',
                    children: [],
                },
                {
                    indexDirectoryCode: '6',
                    indexName: '私募单一',
                    level: '3',
                    indexType: '2',
                    children: [],
                },
                {
                    indexDirectoryCode: '7',
                    indexName: '公募集合',
                    level: '3',
                    indexType: '2',
                    children: [],
                },
                {
                    indexDirectoryCode: '8',
                    indexName: '公募',
                    level: '3',
                    indexType: '2',
                    children: [],
                },
                {
                    indexDirectoryCode: '9',
                    indexName: '私募单一',
                    level: '3',
                    indexType: '2',
                    children: [],
                },
                {
                    indexDirectoryCode: '10',
                    indexName: '公募集合',
                    level: '3',
                    indexType: '2',
                    children: [],
                },
            ];
        }
    }
    // 迁移版本号
    getMoveVersionNums(indexCode) {
        this.$axios.post('/zhiguan/indexArticle/articleDetails/query', { articleCode: indexCode }).then((res: any) => {
            if (res) {
                this.moveIndexArticleCodeList = [];
                let articleDeatilsCodes = [];
                res.forEach(item => {
                    this.moveIndexArticleCodeList.push(item);
                    articleDeatilsCodes.push(item.articleDeatilsCode);
                });
                if (this.indexDetails.moveIndexArticleDetailsCode != '') {
                    if (!articleDeatilsCodes.includes(this.indexDetails.moveIndexArticleDetailsCode)) {
                        this.indexDetails.moveIndexArticleDetailsCode = '';
                    }
                }
            }
        });
    }
    // 迁移条文选择
    changeMovedIndexSource(param) {
        if (param) {
            this.getMoveVersionNums(param);
        } else {
            this.moveIndexArticleCodeList = [];
        }
        this.indexDetails.moveIndexArticleDetailsCode = '';
    }
    // 添加文件来源分类节点
    addFileSourceCategoryNode() {
        this.$axios.post('/indexSource/addFileSourceCategoryNode', { ...this.indexSourceCategoryDetailPo }).then((res: any) => {
            if (res) {
                this.indexDetails.articleCode = res;
                this.addFileBtn = true;
                this.yh_message_success('新增成功!');
                this.$emit('emitAddFileSourceCategoryNode');
                this.addDisabled = true;
            }
        });
    }
    // 新增文件Btn
    handleAddFileBtn(param) {
        this.attachementDialog = true;
        this.typeItem = param;
    }
    // 编辑来源文件
    openAttachementDialog(param1, param2) {
        this.indexDetails.articleCode = param1.articleCode;
        this.indexDetails.articleDeatilsCode = param1.articleDeatilsCode;
        this.$axios.post('/zhiguan/indexArticle/articleDetails/details', { articleDeatilsCode: param1.articleDeatilsCode }).then((res: any) => {
            this.indexDetails.files = [];
            if (this.indexItem.indexType != '2') {
                if (res.moveIndexArticleCode && res.moveIndexArticleDetailsCode) {
                    this.moveIndexSourceIs = true;
                } else {
                    this.moveIndexSourceIs = false;
                }
            } else {
                if (res.moveIndexArticleCode) {
                    this.moveIndexSourceIs = true;
                } else {
                    this.moveIndexSourceIs = false;
                }
            }

            // if (res) {
            this.attachementDialog = true;
            this.typeItem = param2;
            let resList = res;
            if (resList.issueDate) {
                resList.issueDate = res.issueDate.toString();
            }
            if (resList.effectiveDate) {
                resList.effectiveDate = res.effectiveDate.toString();
            }
            this.indexDetails = resList;
            if (this.indexDetails.fileCode) {
                this.indexDetails.fileCode.forEach((element, index) => {
                    this.fileList1.push({
                        name: this.indexDetails.fileName[index],
                        fileNo: element,
                    });
                });
            }
            if (this.indexItem.indexType != '2') {
                if (this.indexDetails.moveIndexArticleCode && this.indexDetails.moveIndexArticleDetailsCode) {
                    this.moveIndexSourceIs = true;
                } else {
                    this.moveIndexSourceIs = false;
                }
            } else {
                if (this.indexDetails.moveIndexArticleCode) {
                    this.moveIndexSourceIs = true;
                } else {
                    this.moveIndexSourceIs = false;
                }
            }

            if (this.indexDetails.moveIndexArticleCode) {
                this.getMoveVersionNums(this.indexDetails.moveIndexArticleCode);
            }
        });
    }
    // 下载
    downloadFileBtn(param1, param2) {
        console.log('文件下载22', param1, param2);
        let data = '';
        if (param2 == '单条下载') {
            if (param1.fileCode[0] == null) {
                this.$message.warning('来源附件为空！');
                return;
            }

            let url = '/apiAssetFile/downLoad';
            if (this.indexItem.indexType === '2') {
                url = '/apiAssetFile/productDownLoad';

                this.$axios({ method: 'post', url: '/apiAssetFile/queryCount', data: { fileId: [param1.fileCode[0]] } }).then((res: any) => {
                    if (res > 0) {
                        downLoadFile({
                            url: '/apiAssetFile/downLoad',
                            method: 'post',
                            data: { fileId: [param1.fileCode[0]], fileName: param1.fileName[0], passWord: this.rsaPassWord },
                        });
                    } else {
                        downLoadFile({
                            url,
                            method: 'post',
                            data: { fileId: [param1.fileCode[0]], fileName: param1.fileName[0], passWord: this.rsaPassWord },
                        });
                    }
                });
            } else {
                downLoadFile({
                    url,
                    method: 'post',
                    data: { fileId: [param1.fileCode[0]], fileName: param1.fileName[0], passWord: this.rsaPassWord },
                });
            }
        }
    }
    comfiredMove(param1, param2) {
        this.delData.moreData = [];
        this.delData.singData = '';
        if (param2 == '单个删除') {
            this.delData.singData = param1.articleDeatilsCode;
            this.delData.moreData = [];
            this.delData.type = param2;
        } else if (param2 == '批量删除') {
            if (param1.length == 0) {
                this.yh_message_warn('请选择来源文件！');
                return;
            }
            let data = [];
            param1.forEach(item => {
                this.delData.moreData.push(item.articleDeatilsCode);
            });
            this.delData.singData = '';
            this.delData.type = param2;
        }
        this.delConfirmationDialog = true;
    }
    handleRemove() {
        if (this.delData.type == '单个删除') {
            this.$axios
                .post('/zhiguan/indexArticle/articleDetails/delete', { articleDeatilsCodeList: [this.delData.singData] })
                .then((res: any) => {
                    this.yh_message_success('删除成功！');
                    this.delConfirmationDialog = false;
                    this.getSourceDetails();
                    this.$emit('emitHandleVaild');
                })
                .catch(() => {
                    this.delConfirmationDialog = false;
                });
        } else if (this.delData.type == '批量删除') {
            this.$axios
                .post('/zhiguan/indexArticle/articleDetails/delete', { articleDeatilsCodeList: this.delData.moreData })
                .then((res: any) => {
                    this.yh_message_success('删除成功！');
                    this.delConfirmationDialog = false;
                    this.getSourceDetails();
                    this.$emit('emitHandleVaild');
                })
                .catch(() => {
                    this.delConfirmationDialog = false;
                });
        }
    }
    // 删除确认窗口显示
    emitDialogVisible(param) {
        this.delConfirmationDialog = param;
    }
    // 多选
    clauseChangeEvent(checked, row, rowIndex) {
        this.multipleitem = [];
        checked.forEach(item => this.multipleitem.push(item));
    }
    // 迁移条文下拉
    getIndexSourceSelect1(data) {
        if (data != '2') {
            this.$axios.post('/zhiguan/indexArticle/article/query', { indexType: data }).then((res: any) => {
                this.indexSourceCodeSelect1 = [];
                res.forEach(item => this.indexSourceCodeSelect1.push(item));
            });
        } else {
            this.$axios.post('/zhiguan/indexArticle/directory/product/query', { indexType: data }).then((res: any) => {
                this.indexSourceCodeSelect1 = [];
                res.forEach(item =>
                    this.indexSourceCodeSelect1.push({
                        articleName: item.indexName,
                        articleCode: item.indexDirectoryCode,
                    })
                );
            });
        }
    }
    handleCommand(command) {
        let data = command.command;
        if (command.index == '0') {
            data.valid = 0;
        } else if (command.index == '1') {
            data.valid = 1;
        }
        this.$axios.post('/zhiguan/indexArticle/articleDetails/update', data).then((res: any) => {
            this.yh_message_success('修改成功!');
            this.getSourceDetails();
            this.$emit('emitHandleVaild');
        });
    }
    beforeHandleCommand(index, command) {
        // index我这里是遍历的角标，即你需要传递的额外参数
        return {
            index: index,
            command: command,
        };
    }
    // 文件上传
    uploadFileSuccess(res, file, fileList, type) {
        console.log('文件上传', res);
        if (res.returnMsg && res.returnMsg !== 'SUCCESS') {
            this.$message.warning(res.returnMsg);
            return;
        }
        this.fileList1.push({
            name: res.data.fileName,
            // url: res.data.relativePath,
            fileNo: res.data.fileId,
        });
    }
    uploadFileError(res, file, fileList, type) {
        this.$message.warning('文件格式不支持!');
    }
    // 下载文件
    downLoadFileBtn2(param) {
        // downLoadFile({
        //     url: '/apiAssetFile/downLoad/' + param.fileNo,
        //     method: 'get',
        // });
        console.log('下载文件', param);
        if (param.fileNo == null) {
            this.$message.warning('来源附件为空！');
            return;
        }

        let url = '/apiAssetFile/downLoad';
        if (this.indexItem.indexType === '2') {
            url = '/apiAssetFile/productDownLoad';

            this.$axios({ method: 'post', url: '/apiAssetFile/queryCount', data: { fileId: [param.fileNo] } }).then((res: any) => {
                if (res > 0) {
                    downLoadFile({
                        url: '/apiAssetFile/downLoad',
                        method: 'post',
                        data: { fileId: [param.fileNo], fileName: param.name, passWord: this.rsaPassWord },
                    });
                } else {
                    downLoadFile({
                        url,
                        method: 'post',
                        data: { fileId: [param.fileNo], fileName: param.name, passWord: this.rsaPassWord },
                    });
                }
            });
        } else {
            downLoadFile({
                url,
                method: 'post',
                data: { fileId: [param.fileNo], fileName: param.name, passWord: this.rsaPassWord },
            });
        }
    }
    // 删除已上传文件
    confirmDelFile1(param) {
        this.fileList1.forEach((item, index) => {
            if (item.fileNo == param.fileNo) {
                this.fileList1.splice(index, 1);
            }
        });
    }
}
</script>
<style lang="scss" scoped>
.source {
    height: calc(98vh - 7px);
    background: #ffffff;
}
</style>
